package clinica;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import org.eclipse.wb.swing.FocusTraversalOnArray;
import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class CadVeterinario extends JFrame {

	private JPanel contentPane;
	private JTextField txtTelefone;
	private JTextField txtNome;
	private JTextField txtSobrenome;
	private JTextField txtEmail;
	private JTextField txtEndereco;
	private JTextField txtCpf;
	private JTextField txtCrmv;
	private int id=1;
	private JTextField txtEspecialidade;
	private JLabel lblId;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CadVeterinario frame = new CadVeterinario();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CadVeterinario() {
		addWindowListener(new WindowAdapter(){
			public void windowActivated(WindowEvent e) {
				lblId.setText(String.valueOf(id));
		}
		});
		
		setTitle("Cadastro De Veterinario\r\n");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 807);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		txtTelefone = new JTextField();
		txtTelefone.setColumns(10);
		txtTelefone.setBounds(35, 350, 279, 20);
		contentPane.add(txtTelefone);
		
		JLabel lblTelefone = new JLabel("Telefone Do Veterinario");
		lblTelefone.setBounds(35, 325, 151, 14);
		contentPane.add(lblTelefone);
		
		JLabel lblCadastrodeVeterinario = new JLabel("Cadastro de Veterinario");
		lblCadastrodeVeterinario.setFont(new Font("Tahoma", Font.PLAIN, 17));
		lblCadastrodeVeterinario.setBounds(59, 32, 175, 21);
		contentPane.add(lblCadastrodeVeterinario);
		
		JLabel lblNome = new JLabel("Nome Do Veterinario");
		lblNome.setBounds(35, 102, 151, 14);
		contentPane.add(lblNome);
		
		txtNome = new JTextField();
		txtNome.setColumns(10);
		txtNome.setBounds(35, 127, 279, 20);
		contentPane.add(txtNome);
		
		JLabel lblSobrenome = new JLabel("Sobrenome Do Veterinario");
		lblSobrenome.setBounds(35, 177, 164, 14);
		contentPane.add(lblSobrenome);
		
		txtSobrenome = new JTextField();
		txtSobrenome.setColumns(10);
		txtSobrenome.setBounds(35, 206, 279, 20);
		contentPane.add(txtSobrenome);
		
		JLabel lblEmail = new JLabel("Email Do Veterinario");
		lblEmail.setBounds(35, 247, 151, 14);
		contentPane.add(lblEmail);
		
		txtEmail = new JTextField();
		txtEmail.setColumns(10);
		txtEmail.setBounds(35, 276, 279, 20);
		contentPane.add(txtEmail);
		
		txtEndereco = new JTextField();
		txtEndereco.setColumns(10);
		txtEndereco.setBounds(35, 438, 279, 20);
		contentPane.add(txtEndereco);
		
		JLabel lblEndereco = new JLabel("Endere\u00E7o Do Veterinario");
		lblEndereco.setBounds(35, 409, 151, 14);
		contentPane.add(lblEndereco);
		
		txtCpf = new JTextField();
		txtCpf.setColumns(10);
		txtCpf.setBounds(35, 520, 279, 20);
		contentPane.add(txtCpf);
		
		JLabel lblCpf = new JLabel("CPF Do Veterinario");
		lblCpf.setBounds(35, 491, 135, 14);
		contentPane.add(lblCpf);
		
		txtCrmv = new JTextField();
		txtCrmv.setColumns(10);
		txtCrmv.setBounds(35, 597, 279, 20);
		contentPane.add(txtCrmv);
		
		JLabel lblCrmv = new JLabel("CRMV Do Veterinario");
		lblCrmv.setBounds(35, 568, 135, 14);
		contentPane.add(lblCrmv);
		
		JLabel lblIdVeterinario = new JLabel("Id Veterinario");
		lblIdVeterinario.setBounds(309, 21, 91, 14);
		contentPane.add(lblIdVeterinario);
		
		lblId = new JLabel("");
		lblId.setBounds(396, 11, 46, 24);
		contentPane.add(lblId);
		
		JLabel lblEspecialidadeDoVeterinario = new JLabel("Especialidade Do Veterinario");
		lblEspecialidadeDoVeterinario.setBounds(35, 642, 224, 14);
		contentPane.add(lblEspecialidadeDoVeterinario);
		
		txtEspecialidade = new JTextField();
		txtEspecialidade.setColumns(10);
		txtEspecialidade.setBounds(35, 671, 279, 20);
		contentPane.add(txtEspecialidade);
		
		JButton btnSalvar = new JButton("Salvar");
		btnSalvar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				DataBase.addMedico(id, txtNome.getText(), txtSobrenome.getText(),
						txtEmail.getText(), txtTelefone.getText(), 
						txtEndereco.getText(), txtCpf.getText(), txtEspecialidade.getText(),
						txtCrmv.getText());
				id++;
				txtNome.setText(null);
				txtSobrenome.setText(null);
				txtEmail.setText(null);
				txtTelefone.setText(null);
				txtEndereco.setText(null);
				txtCpf.setText(null);
				txtEspecialidade.setText(null);
				txtCrmv.setText(null);
				
				dispose();
				
			}
		});
		btnSalvar.setBounds(108, 730, 91, 23);
		contentPane.add(btnSalvar);
		
		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				txtNome.setText(null);
				txtSobrenome.setText(null);
				txtEmail.setText(null);
				txtTelefone.setText(null);
				txtEndereco.setText(null);
				txtCpf.setText(null);
				txtEspecialidade.setText(null);
				txtCrmv.setText(null);
				
				dispose();
			}
		});
		btnCancelar.setBounds(260, 730, 91, 23);
		contentPane.add(btnCancelar);
		setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{txtNome, txtSobrenome, txtEmail, txtTelefone, txtEndereco, txtCpf, txtCrmv, txtEspecialidade, btnSalvar, btnCancelar}));
		}
}

